package com.atguigu.userprofile.mapper;

import com.atguigu.userprofile.bean.UserGroup;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zhangchen
 * @since 2021-05-04
 */


@Mapper
@DS("mysql")
public interface UserGroupMapper extends BaseMapper<UserGroup> {

    @DS("ck")
    @Insert("insert into user_group select #{id}, ${sql} ")
    void writeUserGroupToCk(@Param("id") String id,@Param("sql") String bitmapAndSql);

    //根据分群id，查询人群包
    @DS("ck")
    @Select("select arrayJoin(bitmapToArray(us)) from user_group final where user_group_id = #{id} ")
    List<String> getUserGroupById(@Param("id") String id);

    @DS("ck")
    @Select(" select bitmapCardinality( ${sql} ) ")
    int evaluateUserGroup(@Param("sql") String sql);

    //删除旧的人群包  不支持常规意义的删除，删除其实是alter操作
    @DS("ck")
    @Delete("alter table user_group delete where user_group_id = #{id}")
    void deleteUserGroupById(@Param("id") String id);

}
